// pages/user/userpost/userpost.js
var api = require('../../../utils/api.js');
Page({
  /**
   * 页面的初始数据
   */
  data: {
    page_current: 1,
    page_count:'',
    list_array:'',
    isIpx: api.isIpx ? true : false
  },

  postRequest:function(){
    let that = this;
    api.post({
      url: 'Demand/my',
      data: {
        token: that.data.token,
        page: that.data.page_current
      },
      success: function (data) {
        console.log(data);
        if (data.code == 200) {
          let lists = data.data.lists;
          that.setData({
            list_array: lists
          });
          
          
        }

      }
    });
  },

  delDemand:function(e){
    let that = this;
    api.post({
      url: 'Demand/del',
      data: {
        token: that.data.token,
        did: e.target.id
      },
      success: function (data) {
        console.log(data);
        if (data.code == 200) {
          wx.showToast({
            title: data.data.message,
            icon:'none'
          });
          let list_array = that.data.list_array.filter(function (obj) {
            return e.target.id != obj.did;
          });
          that.setData({
            list_array: list_array
          });
        }
      },
      compete:function(){
      }
    });
    
  },

  // 跳转
  navToDetail: function(e){
    wx.navigateTo({
      url: '../../demandDetail/demandDetail?did=' + e.currentTarget.id,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
        token: api.getStorageData().userbaseinfo.token,
        userinfo: api.getStorageData().userbaseinfo.data,
      });
      this.postRequest();
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})